import { Router, createRouter, createWebHashHistory } from 'vue-router';

import { routes } from './routes';
import { setupRouterGuard } from '@/utils/authentication';

const router: Router = createRouter({
  history: createWebHashHistory(),
  routes,
  strict: true,
  scrollBehavior(to, from, savedPosition) {
    return new Promise(resolve => {
      if (savedPosition) {
        return savedPosition;
      } else {
        if (from.meta.saveSrollTop) {
          const top: number = document.documentElement.scrollTop || document.body.scrollTop;
          resolve({ left: 0, top });
        }
      }
    });
  },
});
// 启用路由跳转拦截
setupRouterGuard(router);

export default router;
